/*
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    2013 year
 *    Author: Esipenko Aleksey (Alexorleon)
 *    E-Mail: alexorleon@gmail.com
 */
#include "global.h"
#include "proxymodel.h"

ProxyModel::ProxyModel(QObject *parent)
    : QSortFilterProxyModel(parent)
{
}

void ProxyModel::clearFilters()
{
    m_performer.clear();
    m_status.clear();
    //m_placement.clear();
    m_date.clear();
    //m_id=0;
    invalidateFilter();
}

bool ProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const {

    if (!m_performer.isEmpty()) {
        QModelIndex index = sourceModel()->index(sourceRow, Performer, sourceParent);
        if (m_performer != sourceModel()->data(index).toString())
            return false;
    }
    if (!m_status.isEmpty()) {
        QModelIndex index = sourceModel()->index(sourceRow, Status, sourceParent);
        if (m_status != sourceModel()->data(index).toString())
            return false;
    }
    /*if (!m_placement.isEmpty()) {
        QModelIndex index = sourceModel()->index(sourceRow, Placement, sourceParent);
        if (m_placement != sourceModel()->data(index).toString())
            return false;
    }*/
    if (!m_date.isEmpty()) {
        QModelIndex index = sourceModel()->index(sourceRow, Date, sourceParent);
        if (m_date != sourceModel()->data(index).toString())
            return false;
    }
    return true;
}

void ProxyModel::setPerformer(const QString &performer)
{
    if (m_performer != performer) {
        m_performer = performer;
        invalidateFilter();
    }
}

void ProxyModel::setStatus(const QString &status)
{
    if (m_status != status) {
        m_status = status;
        invalidateFilter();
    }
}
/*
void ProxyModel::setPlacement(const QString &placement)
{
    if (m_placement != placement) {
        m_placement = placement;
        invalidateFilter();
    }
}
*/
void ProxyModel::setDate(const QString &date)
{
    if (m_date != date) {
        m_date = date;
        invalidateFilter();
    }
}

/*void ProxyModel::setID(const int &id){

    if(m_id != id){
        m_id = id;
        invalidateFilter();
    }
}*/








/*ProxyModel::ProxyModel(QObject *parent)
    : QSortFilterProxyModel(parent)
{
    m_minimumZipcode = m_maximumZipcode = InvalidZipcode;
}


void ProxyModel::clearFilters()
{
    m_minimumZipcode = m_maximumZipcode = InvalidZipcode;
    m_county.clear();
    m_state.clear();
    invalidateFilter();
}


bool ProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const {

    if (m_minimumZipcode != InvalidZipcode ||
        m_maximumZipcode != InvalidZipcode) {
        QModelIndex index = sourceModel()->index(sourceRow, Zipcode,
                                                 sourceParent);
        if (m_minimumZipcode != InvalidZipcode &&
            sourceModel()->data(index).toInt() < m_minimumZipcode)
            return false;
        if (m_maximumZipcode != InvalidZipcode &&
            sourceModel()->data(index).toInt() > m_maximumZipcode)
            return false;
    }
    if (!m_county.isEmpty()) {
        QModelIndex index = sourceModel()->index(sourceRow, County,
                                                 sourceParent);
        if (m_county != sourceModel()->data(index).toString())
            return false;
    }
    if (!m_state.isEmpty()) {
        QModelIndex index = sourceModel()->index(sourceRow, State,
                                                 sourceParent);
        if (m_state != sourceModel()->data(index).toString())
            return false;
    }
    return true;
}


void ProxyModel::setMinimumZipcode(int minimumZipcode)
{
    if (m_minimumZipcode != minimumZipcode) {
        m_minimumZipcode = minimumZipcode;
        invalidateFilter();
    }
}


void ProxyModel::setMaximumZipcode(int maximumZipcode)
{
    if (m_maximumZipcode != maximumZipcode) {
        m_maximumZipcode = maximumZipcode;
        invalidateFilter();
    }
}


void ProxyModel::setCounty(const QString &county)
{
    if (m_county != county) {
        m_county = county;
        invalidateFilter();
    }
}


void ProxyModel::setState(const QString &state)
{
    if (m_state != state) {
        m_state = state;
        invalidateFilter();
    }
}*/
